app.controller("brandController",function($scope,$controller,brandService){
    $scope.list=[];  //列表集合
    $scope.brand ={};// 品牌实体
    $scope.searchEntity = {}; //模糊查询的条件实体
    $controller("baseController",{$scope:$scope});//继承 baseController
    $scope.dele = function(){
        brandService.dele($scope.selectedIds).then(function(result){
            if(result.data.success){
                $scope.reloadList();
            }else {
                alert(result.data.message);
            }
        })
    }
    $scope.findAll = function(){
        //去后台查询数据
        brandService.findAll().then(function(result){
            $scope.list = result.data;
        });
    }

    $scope.edit = function(id){
        //根据ID  查询 品牌
        brandService.findOne(id).then(function(result){
            $scope.brand = result.data;
        });
    }
    $scope.save =function(){
        if($scope.brand.id){
            //编辑方法
            brandService.update($scope.brand).then(function(result){
                if(result.data.success){
                    $scope.reloadList();
                }else{
                    alert(result.data.message);
                }
            });
        }else {
            brandService.save($scope.brand).then(function(result){

                if(result.data.success){
                    $scope.reloadList();
                }else{
                    alert(result.data.message);
                }
            });
        }

    }
    $scope.search = function(page,rows){
        // 当前第几页    每页多少条
        brandService.findPage(page,rows,$scope.searchEntity).then(function(result){
            $scope.list = result.data.rows;
            $scope.pageModel.totalItems = result.data.total;
        });
    }
});